package com.xquant.common.engine.xPP.request;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import java.util.Arrays;
import java.util.List;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class CalcPricingParam {
    private String valueDate;
    private String cfgId;
    private String legId;
    private String peCode = "";
    private String calcPPCode;
    private Ir discount;
    private List<UnderlyingPricingParam> underlyingPricingParams;
    private String princingMode;
    private String fixingType;
    private Ir defaultCurve;
    private  Control control;
    private double MarketNPV;
    /**
     * 信用主体 回收率
     */
    private String recoveryFactor;
    private String aiOffset;
    private String spread;
    /**
     * 计算CDS的CS01时方向控制,0为upNPV-NPV,1为NPV-upNPV
     **/
    private String directionControl;

    /**
     * 多标的相关性
     **/
    private UnderlyingCorr underlyingCorr;


    private Object customPricingParam;
    private List<CalcPricingParam> legParams;

    /**
     * 国债期货新增
     */
    private CtdPricingParam ctdPricingParam;
    /**
     * 国债期货新增
     */
    private List<CtdPricingParam> ctdPricingParams;

    /**
     * 国债期货新增
     */
    private List<CtdIRRPricingParam> ctdIRRPricingParams;

    private String marketPrice;

    private String isInTrade;

    /**
     * 债券新增
     */
    private String exercisedCoupon;

    private String mtrDateType;


    private String marketPriceType;
    /*反算时的计息天数 波动率年化天数，默认365*/
    @JsonProperty(value = "VolAnnualDays")
    private String VolAnnualDays = "365";

    private List<String> keyTerms;

    /*希腊字母偏移*/
    private List<UnderlyGreeksParam> GreeksParams ;

    public List<UnderlyGreeksParam> getGreeksParams() {
        return GreeksParams;
    }

    public CalcPricingParam setGreeksParams(List<UnderlyGreeksParam> greeksParams) {
        GreeksParams = greeksParams;
        return this;
    }

    public String getVolAnnualDays() {
        return VolAnnualDays;
    }

    public CalcPricingParam setVolAnnualDays(String volAnnualDays) {
        this.VolAnnualDays = volAnnualDays;
        return this;
    }

    /**
     * 根据legId获取传入的定价参数，没有则创建空参数,并设置legId
     *
     * @param legId
     * @return
     */
    public CalcPricingParam getCalcPricingParamByLegId(String legId) {
        if (legParams == null) {
            return null;
        }
        CalcPricingParam ret = null;
        for (int i = 0; i < legParams.size(); i++) {
            if (legId.equals(legParams.get(i).getLegId())) {
                return legParams.get(i);
            } else if (legParams.get(i).getLegId() == null) {
                ret = legParams.get(i);
            }
        }
        if (ret == null) {
            ret = new CalcPricingParam();//需要用来存储legId
            ret.setLegId(legId);
        }
        return ret;
    }

    public String getValueDate() {
        return valueDate;
    }

    public CalcPricingParam setValueDate(String valueDate) {
        this.valueDate = valueDate;
        return this;
    }

    public String getCfgId() {
        return cfgId;
    }

    public CalcPricingParam setCfgId(String cfgId) {
        this.cfgId = cfgId;
        return this;
    }

    public String getLegId() {
        return legId;
    }

    public CalcPricingParam setLegId(String legId) {
        this.legId = legId;
        return this;
    }

    public String getPeCode() {
        return peCode;
    }

    public CalcPricingParam setPeCode(String peCode) {
        this.peCode = peCode;
        return this;
    }

    public String getCalcPPCode() {
        return calcPPCode;
    }

    public CalcPricingParam setCalcPPCode(String calcPPCode) {
        this.calcPPCode = calcPPCode;
        return this;
    }

    public Ir getDiscount() {
        return discount;
    }

    public CalcPricingParam setDiscount(Ir discount) {
        this.discount = discount;
        return this;
    }

    public List<UnderlyingPricingParam> getUnderlyingPricingParams() {
        return underlyingPricingParams;
    }

    public CalcPricingParam setUnderlyingPricingParams(List<UnderlyingPricingParam> underlyingPricingParams) {
        this.underlyingPricingParams = underlyingPricingParams;
        return this;
    }

    public String getPrincingMode() {
        return princingMode;
    }

    public CalcPricingParam setPrincingMode(String princingMode) {
        this.princingMode = princingMode;
        return this;
    }

    public String getFixingType() {
        return fixingType;
    }

    public CalcPricingParam setFixingType(String fixingType) {
        this.fixingType = fixingType;
        return this;
    }

    public Ir getDefaultCurve() {
        return defaultCurve;
    }

    public CalcPricingParam setDefaultCurve(Ir defaultCurve) {
        this.defaultCurve = defaultCurve;
        return this;
    }

    public Control getControl() {
        return control;
    }

    public CalcPricingParam setControl(Control control) {
        this.control = control;
        return this;
    }

    public double getMarketNPV() {
        return MarketNPV;
    }

    public CalcPricingParam setMarketNPV(double marketNPV) {
        MarketNPV = marketNPV;
        return this;
    }

    public String getRecoveryFactor() {
        return recoveryFactor;
    }

    public CalcPricingParam setRecoveryFactor(String recoveryFactor) {
        this.recoveryFactor = recoveryFactor;
        return this;
    }

    public String getAiOffset() {
        return aiOffset;
    }

    public CalcPricingParam setAiOffset(String aiOffset) {
        this.aiOffset = aiOffset;
        return this;
    }

    public String getSpread() {
        return spread;
    }

    public CalcPricingParam setSpread(String spread) {
        this.spread = spread;
        return this;
    }

    public String getDirectionControl() {
        return directionControl;
    }

    public CalcPricingParam setDirectionControl(String directionControl) {
        this.directionControl = directionControl;
        return this;
    }

    public UnderlyingCorr getUnderlyingCorr() {
        return underlyingCorr;
    }

    public CalcPricingParam setUnderlyingCorr(UnderlyingCorr underlyingCorr) {
        this.underlyingCorr = underlyingCorr;
        return this;
    }

    public Object getCustomPricingParam() {
        return ObjectUtil.isNull(customPricingParam)?"":customPricingParam;
    }



    public CalcPricingParam setCustomPricingParam(Object customPricingParam) {
        if (JSON.toJSONString(customPricingParam).equals("{}")){
            return this;
        }
        this.customPricingParam = ObjectUtil.isNull(customPricingParam)?"":customPricingParam;
        return this;
    }

    public List<CalcPricingParam> getLegParams() {
        return legParams;
    }

    public CalcPricingParam setLegParams(List<CalcPricingParam> legParams) {
        this.legParams = legParams;
        return this;
    }

    public CtdPricingParam getCtdPricingParam() {
        return ctdPricingParam;
    }

    public CalcPricingParam setCtdPricingParam(CtdPricingParam ctdPricingParam) {
        this.ctdPricingParam = ctdPricingParam;
        return this;
    }

    public List<CtdPricingParam> getCtdPricingParams() {
        return ctdPricingParams;
    }

    public CalcPricingParam setCtdPricingParams(List<CtdPricingParam> ctdPricingParams) {
        this.ctdPricingParams = ctdPricingParams;
        return this;
    }

    public List<CtdIRRPricingParam> getCtdIRRPricingParams() {
        return ctdIRRPricingParams;
    }

    public CalcPricingParam setCtdIRRPricingParams(List<CtdIRRPricingParam> ctdIRRPricingParams) {
        this.ctdIRRPricingParams = ctdIRRPricingParams;
        return this;
    }

    public String getMarketPrice() {
        return marketPrice;
    }

    public CalcPricingParam setMarketPrice(String marketPrice) {
        this.marketPrice = marketPrice;
        return this;
    }

    public String getIsInTrade() {
        return isInTrade;
    }

    public CalcPricingParam setIsInTrade(String isInTrade) {
        this.isInTrade = isInTrade;
        return this;
    }

    public String getExercisedCoupon() {
        return exercisedCoupon;
    }

    public CalcPricingParam setExercisedCoupon(String exercisedCoupon) {
        this.exercisedCoupon = exercisedCoupon;
        return this;
    }

    public String getMtrDateType() {
        return mtrDateType;
    }

    public CalcPricingParam setMtrDateType(String mtrDateType) {
        this.mtrDateType = mtrDateType;
        return this;
    }

    public String getMarketPriceType() {
        return marketPriceType;
    }

    public CalcPricingParam setMarketPriceType(String marketPriceType) {
        this.marketPriceType = marketPriceType;
        return this;
    }

    public List<String> getKeyTerms() {
        return keyTerms;
    }

    public CalcPricingParam setKeyTerms(List<String> keyTerms) {
        this.keyTerms = keyTerms;
        return this;
    }
}
